home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / frontend_implementation / MainFrame.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  5.6 KB  |  131 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. import app
  19. import frontend
  20. import os
  21. from xpcom import components
  22. from util import quoteJS
  23. from frontend_implementation.VideoDisplay import VideoDisplay
  24. from frontend_implementation import urlcallbacks
  25.  
  26. ###############################################################################
  27. #### Main window                                                           ####
  28. ###############################################################################
  29.  
  30. class MainFrame:
  31.     def __init__(self, appl):
  32.         # Symbols by other parts of the program as arguments
  33.         # to selectDisplay
  34.         self.mainDisplay = "mainDisplay"
  35.         self.channelsDisplay = "channelsDisplay"
  36.         self.videoInfoDisplay = "videoInfoDisplay"
  37.  
  38.         # Displays selected in each area, for generating deselection
  39.         # messages.
  40.         self.selectedDisplays = {}
  41.         urlcallbacks.installMainDisplayCallback(self.mainDisplayCallback)
  42.  
  43.     def onSelectedTabChange(self, states, actionGroups, guideURL,
  44.             videoFilename):
  45.         app.controller.setGuideURL(guideURL)
  46.         if videoFilename is not None:
  47.             frontend.jsBridge.updateVideoFilename(os.path.basename(videoFilename))
  48.         else:
  49.             frontend.jsBridge.updateVideoFilename('')
  50.         frontend.currentVideoPath = videoFilename
  51.         for group, enabled in actionGroups.items():
  52.             frontend.jsBridge.setActionGroupEnabled(group, enabled)
  53.  
  54.         # Convert this into something JavaScript can see
  55.         array_cls = components.classes["@mozilla.org/supports-array;1"]
  56.         variant_cls = components.classes["@mozilla.org/variant;1"]
  57.         stateLists = array_cls.createInstance()
  58.         stateLists = stateLists.queryInterface(components.interfaces.nsICollection)
  59.         for key, actions in states.items():
  60.             newactions = array_cls.createInstance()
  61.             newactions = newactions.queryInterface(components.interfaces.nsICollection)
  62.             for action in actions:
  63.                 newaction = variant_cls.createInstance()
  64.                 newaction = newaction.queryInterface(components.interfaces.nsIWritableVariant)
  65.                 newaction.setAsAString(action)
  66.                 newactions.AppendElement(newaction)
  67.             newlist = array_cls.createInstance()
  68.             newlist = newlist.queryInterface(components.interfaces.nsICollection)
  69.             newkey = variant_cls.createInstance()
  70.             newkey = newkey.queryInterface(components.interfaces.nsIWritableVariant)
  71.             newkey.setAsAString(key)
  72.             newlist.AppendElement(newkey)
  73.             newactions = newactions.queryInterface(components.interfaces.nsISupportsArray)
  74.             newlist.AppendElement(newactions)
  75.             stateLists.AppendElement(newlist)
  76.  
  77.         stateLists.queryInterface(components.interfaces.nsISupportsArray)
  78.         frontend.jsBridge.updateMenus(stateLists)
  79.         
  80.     def selectDisplay(self, newDisplay, area):
  81.         """Install the provided 'newDisplay' in the requested area"""
  82.  
  83.         # Generate a deselection message for the previously selected
  84.         # display in this area, if any
  85.         if area in self.selectedDisplays:
  86.             oldDisplay = self.selectedDisplays[area]
  87.             if oldDisplay:
  88.                 oldDisplay.onDeselected_private(self)
  89.                 oldDisplay.onDeselected(self)
  90.                 oldDisplay.removedFromArea()
  91.  
  92.         # Generate a selection message for the new display, if any
  93.         self.selectedDisplays[area] = newDisplay
  94.         if newDisplay:
  95.             newDisplay.onSelected_private(self)
  96.             newDisplay.onSelected(self)
  97.             newDisplay.setArea(area)
  98.         if area == self.mainDisplay:
  99.             if isinstance(newDisplay, VideoDisplay):
  100.                 frontend.jsBridge.showVideoDisplay()
  101.             else:
  102.                 frontend.jsBridge.hideVideoDisplay()
  103.                 frontend.jsBridge.leaveFullscreen()
  104.  
  105.     def mainDisplayCallback(self, url):
  106.         try:
  107.             display = self.selectedDisplays[self.mainDisplay]
  108.             if hasattr (display, "onURLLoad"):
  109.                 return self.selectedDisplays[self.mainDisplay].onURLLoad(url)
  110.             else:
  111.                 return True
  112.         except KeyError:
  113.             return True
  114.  
  115.     def getDisplay(self, area):
  116.         return self.selectedDisplays.get(area)
  117.  
  118.     # Internal use: return an estimate of the size of a given display area
  119.     # as a (width, height) pair, or None if no information's available.
  120.     def getDisplaySizeHint(self, area):
  121.         return None
  122.  
  123.     def unlink(self):
  124.         pass
  125.  
  126.     def __del__(self):
  127.         self.unlink()
  128.  
  129. ###############################################################################
  130. ###############################################################################
  131.